package com.bravo.mvp.ui.main;

import com.bravo.mvp.base.BasePersenter;

/**
 * Created by Administrator on 2017/8/7.
 */

public class MainPersenter extends BasePersenter<MainView> implements ModuleListener {

    private final MainModule mainModule;

    public MainPersenter() {
        mainModule = new MainModuleImp(this);
    }

    public void doAdd() {
        int number = getNowNumber();
        mainModule.doAdd(number);
    }

    private int getNowNumber() {
        if (isViewAttached()) {
            return mActView.get().getTvNumber();
        }
        return -1;
    }

    @Override
    public void addFinish(int i) {
        if (isViewAttached()){
            mActView.get().setTvNumber(String.valueOf(i));
        }
    }

    @Override
    public void onAddError(Exception e) {
        if (isViewAttached()){
            mActView.get().onRespondError(e.getMessage());
            mActView.get().setTvNumber("0");
        }
    }
}
